package com.itheima.d5_recursion;

/**
 * 目标：掌握递归的应用，执行流程和算法思想。
 */
public class RecursionTest2 {
    public static void main(String[] args) {
        long result = f(5);
        System.out.println("result = " + result);

        long sum = sum(5);
        System.out.println("sum = " + sum);
    }

    /*
    * f(n) = f(n-1) * n
    * f(1) = 1
    * */

    public static long f(int n) {
        if (n == 1) {
            return 1;
        }
        return f(n - 1) * n;
    }

    public static long sum(int n) {
        if (n == 1) {
            return 1;
        }else {
            return sum(n - 1) + n;
        }
    }

}
